#ifndef MPDSERVER_H
#define MPDSERVER_H

#include <QObject>
#include <QtNetwork/QHostAddress>
#include <QList>

class QTcpServer;
class QTcpSocket;

struct StatusInfo
{
    quint16         volume;
    bool            repeat;
    bool            single;
    bool            consume;
    quint32         playlistversion;
    quint32         playlistlength;
    QString         state;
    quint32         song;
    quint32         songid;
    quint32         nextsong;
    quint32         nextsongid;
    quint32         time;
    quint32         elapsed;
    quint16         bitrate;
    quint16         xfade;
    QString         audio;
    quint16         jobid;
    QString         error;
};

struct SongInfo
{
    QString title;
    QString artist;
    QString album;
};

class MpdServer : public QObject
{
    Q_OBJECT
public:
    explicit MpdServer(QHostAddress address, quint16 port, QObject *parent = 0);
    virtual ~MpdServer();
signals:

public slots:

protected slots:

    void clientDisconnected             ();
    void acceptConnection               ();
    void parseIncoming                  ();
    void parseIncoming                  (QTcpSocket* sock);

signals:
    void statusRequested                (StatusInfo* args);
    void currentSongRequested           (SongInfo* args);

private:
    void reportStatus                   (QTcpSocket* sock, const StatusInfo* args);
    void reportCurrentSong              (QTcpSocket* sock, const SongInfo* args);
private:
    QTcpServer* _srv;
    QList<QTcpSocket*> _clients;
};

#endif // MPDSERVER_H
